package cn.iocoder.yudao.module.trade.scan.vo;

import cn.iocoder.yudao.framework.business.order.pojo.dto.OrderSubmitDTO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/02/24
 */
@Schema(description = "线下扫码订单创建 VO")
@Data
@Valid
public class ScanOrderSubmitDTO extends OrderSubmitDTO {

    @Schema(description = "店铺编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    @NotNull(message = "店铺编号不能为空")
    private Long shopId;

    @Schema(description = "金额，单位为分", example = "100")
    @Min(value = 1, message = "金额必须大于 0")
    @NotNull(message = "金额不能为空")
    private Integer price;

    @Schema(description = "备注", example = "你说的对")
    private String remark;

    @Schema(description = "是否使用积分抵扣", defaultValue = "false", example = "false")
    private Boolean usePointDeduction;

    @Schema(description = "是否使用联盟豆抵扣", defaultValue = "false", example = "false")
    private Boolean useCryptocurrencyDeduction;

    @Schema(description = "是否使用会员价", defaultValue = "false", example = "false")
    private Boolean useVipPrice;

    @Schema(description = "是否使用红包抵扣", defaultValue = "false", example = "false")
    private Boolean useRedPacketDeduction;

    @Schema(description = "是否使用优惠券抵扣", defaultValue = "false", example = "false")
    private Boolean useCouponDeduction;

    @Schema(description = "优惠劵编号。客户于 2025/05/27 欲增加该功能", example = "0")
    private Long couponId;

    @SuppressWarnings("unused")
    @AssertTrue(message = "会员价不能与其他优惠同时享受")
    @JsonIgnore
    public boolean validateVipPrice() {
        if (Boolean.TRUE.equals(useVipPrice)) {
            return !Boolean.TRUE.equals(usePointDeduction)
                   && !Boolean.TRUE.equals(useCryptocurrencyDeduction)
                   && !Boolean.TRUE.equals(useRedPacketDeduction)
                   && !Boolean.TRUE.equals(useCouponDeduction);
        }
        return true;
    }

    @SuppressWarnings("unused")
    @AssertTrue(message = "积分抵扣不能与其他优惠同时享受")
    @JsonIgnore
    public boolean validatePointDeduction() {
        if (Boolean.TRUE.equals(usePointDeduction)) {
            return !Boolean.TRUE.equals(useVipPrice)
                   && !Boolean.TRUE.equals(useCryptocurrencyDeduction)
                   && !Boolean.TRUE.equals(useRedPacketDeduction)
                   && !Boolean.TRUE.equals(useCouponDeduction);
        }
        return true;
    }

    @SuppressWarnings("unused")
    @AssertTrue(message = "联盟豆抵扣不能与其他优惠同时享受")
    @JsonIgnore
    public boolean validateCryptocurrencyDeduction() {
        if (Boolean.TRUE.equals(useCryptocurrencyDeduction)) {
            setUseCryptocurrencyDeduction(true);
            return !Boolean.TRUE.equals(useVipPrice)
                   && !Boolean.TRUE.equals(usePointDeduction)
                   && !Boolean.TRUE.equals(useRedPacketDeduction)
                   && !Boolean.TRUE.equals(useCouponDeduction);
        }
        return true;
    }

    @SuppressWarnings("unused")
    @AssertTrue(message = "红包抵扣不能与其他优惠同时享受")
    @JsonIgnore
    public boolean validateRedPacketDeduction() {
        if (Boolean.TRUE.equals(useRedPacketDeduction)) {
            return !Boolean.TRUE.equals(useVipPrice)
                   && !Boolean.TRUE.equals(usePointDeduction)
                   && !Boolean.TRUE.equals(useCryptocurrencyDeduction)
                   && !Boolean.TRUE.equals(useCouponDeduction);
        }
        return true;
    }

    @SuppressWarnings("unused")
    @AssertTrue(message = "优惠券不能与其他优惠同时享受")
    @JsonIgnore
    public boolean validateCoupon() {
        if (Boolean.TRUE.equals(useCouponDeduction)) {
            return !Boolean.TRUE.equals(useVipPrice)
                   && !Boolean.TRUE.equals(usePointDeduction)
                   && !Boolean.TRUE.equals(useCryptocurrencyDeduction)
                   && !Boolean.TRUE.equals(useRedPacketDeduction);
        }
        return true;
    }

}
